// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TOutput.java

package presenter;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.PrintStream;
import javax.swing.*;

// Referenced classes of package presenter:
//            SongFile

public class TOutput extends JLabel
    implements ActionListener
{

    public TOutput()
    {
        this(800, 600);
    }

    public TOutput(int width, int height)
    {
        id = 0;
        verse = 0;
        wraplimit = 40;
        t = new Timer(25, this);
        t.start();
        out = "<html>";
        this.width = width;
        this.height = height;
        setSize(width, height);
        setHorizontalAlignment(0);
        setHorizontalTextPosition(0);
        fontSize = 12;
        clear = false;
        capitalized = false;
        jlp = new JLayeredPane();
        video = false;
        jlp.add(this);
        setForeground(Color.WHITE);
        jlp.setSize(width, height);
        jlp.setVisible(true);
        jd = new JFrame();
        jd.setContentPane(this);
        jd.setDefaultCloseOperation(2);
        jd.setUndecorated(true);
        jd.setSize(width, height);
    }

    public void setDefaultSong(SongFile defaultSong)
    {
        this.defaultSong = defaultSong;
        if(output == null || !current.hasCustomBackground())
            setBackground(new File(defaultSong.getBackground()));
        if(current == null || !current.hasCustomColor())
            setForeground(defaultSong.getColor());
    }

    public void setSong(SongFile song)
    {
        current = song;
        if(current.hasCustomBackground())
        {
            setBackground(new File(current.getBackground()));
            if(background.getIconWidth() != getWidth())
            {
                Image temp = background.getImage();
                temp = temp.getScaledInstance(getWidth(), getHeight(), 0);
                background = new ImageIcon(temp);
                setIcon(background);
            }
        }
        if(current.hasCustomColor())
            setForeground(current.getColor());
        else
            setForeground(defaultSong.getColor());
    }

    public void setCapitalized(boolean b)
    {
        capitalized = b;
    }

    public void setUndecorated(boolean b)
    {
        jd.setUndecorated(b);
    }

    public void setVisible(boolean b)
    {
        jd.setVisible(b);
    }

    public void clear()
    {
        if(clear)
        {
            if(output != null)
            {
                //System.out.println(output[0]);
                setText(output);
            }
        } else
        {
            setText("");
        }
        clear = !clear;
    }

    public boolean getLive()
    {
        return live;
    }

    public void setLive(boolean live)
    {
        this.live = live;
    }

    public void setClear(boolean clear)
    {
        this.clear = clear;
    }

    public void black()
    {
        if(isVisible())
        {
            jd.setBackground(Color.BLACK);
            setVisible(false);
        } else
        {
            jd.setBackground(Color.GRAY);
            setVisible(true);
        }
    }

    public int getID()
    {
        if(current == null)
            return 0;
        else
            return current.getNumber();
    }

    public int getVerse()
    {
        return verse;
    }

    public boolean hasVideo()
    {
        return video;
    }

    public void setVideo(boolean b)
    {
        video = b;
    }

    public void setVerse(int verse)
    {
        this.verse = verse;
    }

    public void setFont(String font)
    {
        this.font = new Font(font, 0, fontSize);
    }

    public void setText(String output[])
    {
        String temp;
        int j;
        if(output == null)
        {
            output = new String[1];
            output[0] = " ";
        }
        this.output = output;
        temp = "";
        out = "<html> <p style=\"text-align: center;\">";
        j = 0;
_L2:
        if(j >= output.length)
            break; /* Loop/switch isn't completed */
        temp = output[j];
        if(output[j].length() > wraplimit)
        {
            int start = output[j].length() / 2;
            int i = 0;
            do
            {
                if(i >= output[j].length() / 2)
                    break;
                String x = output[j].substring(start - i, (start - i) + 1);
                String y = output[j].substring(start + i, start + i + 1);
                if(x.equals(" "))
                {
                    temp = (new StringBuilder()).append(output[j].substring(0, (start - i) + 1)).append("<br>").append(output[j].substring(start - i, output[j].length())).toString();
                    //System.out.println((new StringBuilder()).append("updated to ").append(temp).toString());
                    break;
                }
                if(y.equals(" "))
                {
                    temp = (new StringBuilder()).append(output[j].substring(0, start + i + 1)).append("<br>").append(output[j].substring(start + i, output[j].length())).toString();
                    break;
                }
                i++;
            } while(true);
        }
        if(capitalized)
            temp = temp.toUpperCase();
        new StringBuilder();
        this;
        JVM INSTR dup_x1 ;
        out;
        append();
        temp;
        append();
        "<br>";
        append();
        toString();
        out;
        j++;
        if(true) goto _L2; else goto _L1
_L1:
        new StringBuilder();
        this;
        JVM INSTR dup_x1 ;
        out;
        append();
        "</p></html>";
        append();
        toString();
        out;
        super.setText(out);
        updateFont();
        if(!isVisible())
            setVisible(true);
        return;
    }

    public boolean isClear()
    {
        return clear;
    }

    public void updateFont()
    {
        Graphics g = getGraphics();
        if(font == null)
            font = g.getFont();
        if(g == null)
            //System.out.println("makes no sense");
        if(g != null)
        {
            FontMetrics fm = g.getFontMetrics(font);
            int height = 0;
            int maxLength = 0;
            int largestWidth = 0;
            for(int index = 0; index < output.length; index++)
            {
                Rectangle2D rect = fm.getStringBounds(output[index].toUpperCase(), g);
                height += (int)rect.getHeight();
                if(output[index].length() > wraplimit)
                {
                    height += (int)rect.getHeight();
                    if((int)((rect.getWidth() * 2D) / 3D) > largestWidth)
                    {
                        //System.out.println((new StringBuilder()).append(index).append(" ").append(rect.getWidth()).toString());
                        maxLength = index;
                        largestWidth = (int)((rect.getWidth() * 2D) / 3D);
                    }
                    continue;
                }
                if((int)rect.getWidth() > largestWidth)
                {
                    maxLength = index;
                    largestWidth = (int)rect.getWidth();
                }
            }

            double heightRatio = ((double)getHeight() - (double)getHeight() / 16D) / (double)height;
            double widthRatio = ((double)getWidth() - (double)getWidth() / 16D) / (double)largestWidth;
            //System.out.println((new StringBuilder()).append(largestWidth).append(" ").append(widthRatio).append(" ").append(height).append(" ").append(heightRatio).toString());
            if(heightRatio >= widthRatio)
            {
                fontSize = (int)((double)fontSize * widthRatio);
                height = (int)((double)height * widthRatio);
            } else
            {
                fontSize = (int)((double)fontSize * heightRatio);
                height = (int)((double)height * heightRatio);
            }
            setFont(font.getFontName());
            g.setFont(font);
            g.setColor(Color.RED);
            setFont(font);
            super.getGraphics().setColor(Color.RED);
            //System.out.println((new StringBuilder()).append("font size ").append(font.getSize()).toString());
        }
    }

    public void setBackground(File f)
    {
        background = new ImageIcon(Toolkit.getDefaultToolkit().getImage(f.getPath()));
        setIcon(background);
    }

    public void changeLocation(int x, int y)
    {
        jd.setLocation(x, y);
        //System.out.println(jd.getLocation());
    }

    public void changeSize(int x, int y)
    {
        jd.setSize(x, y);
        setSize(x, y);
        if(background.getIconWidth() != getWidth())
        {
            Image temp = background.getImage();
            temp = temp.getScaledInstance(getWidth(), getHeight(), 0);
            background = new ImageIcon(temp);
            setIcon(background);
        }
    }

    public void setBackground(Image img)
    {
        if(img != null)
        {
            setIcon(new ImageIcon(img));
            background = new ImageIcon(img);
            if(background.getIconWidth() != getWidth())
            {
                Image temp = background.getImage();
                temp = temp.getScaledInstance(getWidth(), getHeight(), 0);
                background = new ImageIcon(temp);
                setIcon(background);
            }
        }
    }

    public static void main(String args[])
    {
        TOutput to = new TOutput();
        String input[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
        String x[] = {
            "This is A test", "This should work", "line3", "line4"
        };
        to.setText(x);
    }

    public void actionPerformed(ActionEvent actionevent)
    {
    }

    String out;
    String output[];
    Font font;
    int fontSize;
    int width;
    int height;
    private boolean video;
    int id;
    int verse;
    Timer t;
    JFrame jd;
    private boolean clear;
    private boolean live;
    private boolean capitalized;
    private JLayeredPane jlp;
    private SongFile sf;
    private ImageIcon background;
    private JFrame j;
    private int wraplimit;
    private SongFile defaultSong;
    private SongFile current;
}
